﻿@model TomNet.App.Model.DB.Identity.Users
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>InterfaceEdit</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="~/lib/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="~/css/font.css">
    @* <script src="~/jquery/dist/jquery.min.js"></script>*@
    <script src="~/lib/layui/layui.js" charset="utf-8"></script>
    <style>
        .layui-input-block {
            width: 210px;
        }

            .layui-input-block.big {
                width: 545px;
            }

        .layui-anim.layui-anim-upbit {
            max-height: 140px;
        }

        textarea {
            height: 76px !important;
            resize: none
        }
    </style>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">

                        <form class="layui-form" action="">
                            <input type="hidden" id="id" name="id" value="@Model.Id" />
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">用户名称</label>
                                    <div class="layui-input-block">
                                        <input type="text" size="24" id="names" name="names" value="@Model.UserName" placeholder="请输入用户名称" required lay-verify="required" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">修改密码</label>
                                    <div class="layui-input-block">
                                        <input type="text" size="24" id="password" value="@ViewBag.password" name="password" placeholder="请输入密码" required lay-verify="required" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">邮箱Email</label>
                                    <div class="layui-input-block">
                                        <input type="text" size="24" id="email" name="email" value="@Model.Email" placeholder="请输入邮箱" required lay-verify="required" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">联系电话</label>
                                    <div class="layui-input-block">
                                        <input type="text" size="24" id="phone" name="phone" value="@Model.Phone" oninput="value=value.replace(/[^\d]/g,'')" placeholder="请输入联系方式" required lay-verify="required" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">身份证号</label>
                                    <div class="layui-input-block">
                                        <input type="text" size="24" id="idNumber" name="idNumber" value="@Model.IdNumber" placeholder="请输入身份证号" required lay-verify="required" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">用户归属</label>
                                    <div class="layui-input-block">
                                        <select name="interfaceID" id="interfaceID" lay-verify="required">
                                            <option id="interfacevalue"></option>
                                        </select>
                                    </div>
                                </div>
                                @*<div class="layui-inline">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="1" title="男" checked lay-filter="sex">
                    <input type="radio" name="sex" value="0" title="女" lay-filter="sex">
                </div>
            </div>*@
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="button" class="layui-btn" lay-submit lay-filter="form">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-danger" style="width:100px;">重置</button>
                                </div>
                            </div>
                        </form>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        var sex, interfaceId, interfacevalue;
        layui.use(['layer', 'form'], function () {
            var $ = layui.$;
            var form = layui.form;
            var layer = layui.layer;
            $.ajax({
                type: 'POST',
                url: '/User/UserList/?intType=3',
                datatype: 'json',
                success: function (data) {                    
                    if (data.code == 0) {
                        for (var i = 0; i < data.data.length; i++) {                            
                            if (data.data[i].userId == @ViewBag.interfaceId) {                               
                                interfaceId = data.data[i].userId;
                                interfacevalue = data.data[i].userName;
                                $('#interfacevalue').append(data.data[i].userName);
                             }
                        }
                        $.each(data.data, function (index, item) {
                            if (item.userId !=@ViewBag.interfaceId) {
                                $('#interfaceID').append(new Option(item.userName, item.userId));
                            }
                        });
                        form.render('select');
                    }
                }
            });            
            @*if ('@Model.Sex' =='True') {

                $("input:radio[name=sex][value=1]").attr("checked", true);
            } else {
                $("input:radio[name=sex][value=0]").attr("checked", true);
            }
            form.render();
            form.on('radio(sex)', function (data) {
                sex = data.value;
            });*@

            form.on('submit(form)', function (data) {
                var id = $('#id').val().trim();
                var Name = $('#names').val().trim();
                var RoleName = $('#RoleName').val().trim();
                var email = $('#email').val().trim();
                var phone = $('#phone').val().trim();
                var idNumber = $('#idNumber').val().trim();
                var password = $('#password').val().trim();
                var InterfaceID = ($('#interfaceID').val() == interfacevalue ? interfaceId : $('#interfaceID').val());                    
                //if (typeof (sex) == 'undefined') {
                //    sex = 1;
                //}
                if ('@Model.Sex' == 'True') {
                    sex = 1;
                }
                else {
                    sex = 0;
                }
                $.ajax({
                    type: 'POST',
                    url: '/User/AgentEdit',
                    data: { UserId: id, LoginId:@ViewBag.loginid, UserName: Name, Email: email, Phone: phone, IdNumber: idNumber, Sex: sex, RoleID: RoleName, Password: password,InterfaceID: InterfaceID },
                    datatype: 'json',
                    success: function (data) {
                        if (data.type == 200) {
                            layer.alert(data.content, { icon: 6 }, function () {
                                closeself();
                            });

                        } else {
                            layer.alert("添加失败，或者权限不够", { icon: 5 });
                        }
                    }
                });
                return false;
            });
            var closeself = function () {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }
        });
    </script>
</body>
</html>
